/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.broker.mapper;

import java.util.List;
import java.util.Map;

import me.send.broker.entity.UserEvaluate;
import me.send.broker.pojo.BrokerEvaluateBean;
import me.send.broker.pojo.UserEvaluateBean;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * @author maxmin
 *
 * @date 2015年8月25日 下午4:55:47
 */
public interface UserEvaluateMapper {
	/**
	 * 添加对用户的评论
	 * @param evaluate
	 * @return
	 * @author maxmin
	 * @date 2015年8月25日下午5:15:21
	 */
	@Insert(value="INSERT INTO user_evaluate (point,content,orderid,brokerid,createtime,updatetime) "
			+ "VALUES (#{point},#{content},#{orderid},#{brokerid},#{createtime},#{updatetime})")
	public int addUserEvaluate(UserEvaluate evaluate);
	
	@Select(value = "SELECT DISTINCT ue.content,ue.createtime,p.username,"
			+ "p.headerpath,ue.point,ue.evaluate_id,o.orderid,ue.brokerid,p.sex "
			+ "FROM user_evaluate ue LEFT JOIN orders o ON o.orderid = ue.orderid "
			+ "LEFT JOIN `user` u ON o.userid = u.userid LEFT JOIN popuser p "
			+ "ON ue.brokerid = p.popid WHERE o.userid=#{userid}")
	@Results({
		@Result(column="evaluate_id",property="evaluateid")
	})
	public List<UserEvaluateBean> getEvaluates(int userid); 
	
	
	@Select(value = "SELECT DISTINCT ue.content, ue.createtime, ue.point, ue.evaluate_id, u.nickname "
			+ "FROM user_evaluate ue LEFT JOIN orders o ON o.orderid = ue.orderid "
			+ "LEFT JOIN `user` u ON o.userid = u.userid  WHERE ue.brokerid = #{brokerid} "
			+ "AND IF(#{startId}>0,ue.evaluate_id<#{startId},1=1) ORDER BY ue.evaluate_id DESC LIMIT #{size}")
	@Results({
		@Result(column="evaluate_id",property="evaluateid")
	})
	public List<BrokerEvaluateBean> getMyEvaluates(Map<String, Object> params);
}
